<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<html>
<head>
    <meta charset="UTF-8">
    <script src="/js/axios.js/"></script>
    <script src="/js/vue.js"></script>
    <script src="/el/element.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/mystyle.css" >
    <link rel="stylesheet" type="text/css" href="/el/element.css" />
    <title>登录</title>
</head>
<body>
<div id="app" style="text-align: center;margin-top: 20px">
    <div th:replace="~{common/head-index::head}"></div>
    <div style="margin-top: 80px">
    <h3> 添加新的博文类型</h3>
    <p><el-input  placeholder="请输入类型" style="width:300px"  v-model="blogtype.type"> </el-input>
    </p>
    <el-button @click="addtype" :disabled="blogtype.type==''">添加</el-button>
     <el-button><a href="/api/public/goHome">返回首页</a></el-button>
    </div>
</div>
</body>
<script>
    var app = new Vue({
        el : "#app",
        data : {
            user : {
                username : "",
                password  : "",
            },
            blogtype :{
                type : ""
            },
            isLogin : false,
            loginUser : {

            }


        },
        methods : {
            outLogin() {
                sessionStorage.clear()
                localStorage.clear()
            },
            addtype(){
                let _this = this
                axios.post("/api/user/type/addType",this.blogtype).then(function (resp) {
                    if (resp.data.data ==false){
                        _this.$message({
                            message: '该类型已经存在！！',//提示的信息
                            type:'error',　　
                        });
                    } else{
                        _this.$message({
                            message: '添加成功！！',//提示的信息
                            type:'success',
                            duration:600,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
                            onClose:()=>{
                                top.location.href="/api/user/go2FindInfo"
                            }
                        });

                    }
                })
            },
            login() {
                let _this = this
                console.log(this.user)
                axios({
                    url : "/api/public/login",
                    method : "post",
                    headers:{ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                    params:_this.user

                }).then(function (resp) {
                    console.log(resp.data)
                    if (resp.data.code==0){
                        // sessionStorage.setItem("username",_this.user.username)
                        // sessionStorage.setItem("isLogin",true)
                        _this.$message({
                            message: '登录成功！',//提示的信息
                            type:'success',　　//类型是成功
                            offset:225,　　//距离窗口顶部的偏移量，建议不设置
                            duration:1200,　　//显示时间, 毫秒。设为 0 则不会自动关闭，建议1200
                            onClose:()=>{
                                top.location.href =resp.data.action;
                            }
                        });
                    }else{
                        console.log(resp.data)
                        alert(resp.data.msg)
                    }
                });
            },
        },
        mounted() {
            let _this = this;
            _this.loginUser =JSON.parse(sessionStorage.getItem("user"));
            axios.get("/api/public/whetherLogin").then(function (resp) {
                _this.isLogin = resp.data.data
            })
        }


    })
</script>

</html>